package 网络编程.udp协议通信;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class 服务端 {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(9999);
        byte[] data = new byte[1024 * 64];
        while(true) {
            DatagramPacket packet = new DatagramPacket(data, data.length);
            socket.receive(packet);
            System.out.println(new String(data, 0, packet.getLength()));
            System.out.println(packet.getAddress());
            System.out.println(packet.getPort());
        }
    }
}
